home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
mathtu1a
/
tutorfrm.frm
< prev
Wrap
Text File
|
1999-10-07
|
9KB
|
301 lines
VERSION 5.00
Begin VB.Form TutorFrm
BorderStyle = 1 'Fixed Single
Caption = "Math Tutor"
ClientHeight = 855
ClientLeft = 45
ClientTop = 615
ClientWidth = 2175
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 855
ScaleWidth = 2175
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox Answer
Height = 285
Left = 120
MultiLine = -1 'True
TabIndex = 3
ToolTipText = "Answer"
Top = 480
Width = 1935
End
Begin VB.TextBox Problem
Enabled = 0 'False
Height = 285
Left = 120
Locked = -1 'True
TabIndex = 2
ToolTipText = "Math Problem"
Top = 120
Width = 1935
End
Begin VB.ListBox TimeLst
Height = 255
Left = 120
TabIndex = 1
Top = 0
Visible = 0 'False
Width = 135
End
Begin VB.Timer Time
Interval = 1000
Left = 240
Top = 0
End
Begin VB.ListBox OptionT
Height = 255
Left = 0
TabIndex = 0
Top = 0
Visible = 0 'False
Width = 135
End
Begin VB.Menu PauseCmd
Caption = "&Pause"
End
Begin VB.Menu StopCmd
Caption = "&Stop"
End
Begin VB.Menu ExitCmd
Caption = "&Exit"
End
End
Attribute VB_Name = "TutorFrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Name: Math Tutor
'Author: InfraRed
'Contact Info: ICQ #: 17948286
' E-Mail: InfraRed@flashmail.com
'----------------Code Starts Here------------------
Dim AnswerN As Long
Dim NumWrong As Integer
Dim NumRight As Integer
Dim CurTime As Integer
Private Sub Answer_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then 'Here we are finding returns, deleting them, and activating the answer checker
KeyAscii = 0
CheckA
Exit Sub
End If
Const Numbers$ = "0123456789"
If KeyAscii <> 8 Then 'This part will only let numbers go though, so people cannot type in letters/other characters and cause an error
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
Exit Sub
End If
End If
End Sub
Public Sub CheckA()
If Answer.Text = "" Then 'Make sure the text box isn't empty
Exit Sub
End If
If Answer.Text = AnswerN Then 'See if the answer is correct
'Answer is correct, add to the right number and restart the questions
NumRight = NumRight + 1
Time.Enabled = False
Time.Enabled = True
If CurTime > 1 Or CurTime < 1 Then
TimeLst.AddItem CurTime & " seconds"
Else
TimeLst.AddItem CurTime & " second"
End If
CurTime = 0
Answer.Text = ""
GenQ
Else 'Answer isn't correct, so add to the wrong number and give them a msgbox
NumWrong = NumWrong + 1
MsgBox "Wrong answer!", 48, "Wrong"
End If
End Sub
Public Sub StopT() 'This will stop the tutor and give people their "scores"
Dim i As Integer
Answer.Text = ""
Problem.Text = ""
PauseCmd.Caption = "Pause"
StatsFrm.Show
StatsFrm.NumRight.Caption = NumRight
StatsFrm.NumWrong.Caption = NumWrong
StatsFrm.Times.Clear
For i = 0 To TimeLst.ListCount - 1
StatsFrm.Times.AddItem TimeLst.List(i)
Next i
TutorFrm.Hide
End Sub
Public Sub GenQ() 'Here is where the question is generated
Dim RndNum As Integer
Dim Num1 As Long
Dim Num2 As Long
Dim RNum1 As Long
Dim RNum2 As Long
Dim NumA As Long
Randomize Timer
'Pick one of the math types selected before
RndNum = Int(((OptionT.ListCount - 1) - 0 + 1) * Rnd)
RndNum = OptionT.List(RndNum)
'Here is where we calculate what numbers should be used in the problem
'--------------------------------------------------
If RndNum < 2 Then
If SetupFrm.OptionD(0).Value = True Then
Num1 = Int((10 - 1 + 1) * Rnd + 1)
Num2 = Int((10 - 1 + 1) * Rnd + 1)
ElseIf SetupFrm.OptionD(1).Value = True Then
Num1 = Int((100 - 1 + 1) * Rnd + 1)
Num2 = Int((100 - 1 + 1) * Rnd + 1)
Else
Num1 = Int((1000 - 1 + 1) * Rnd + 1)
Num2 = Int((1000 - 1 + 1) * Rnd + 1)
End If
ElseIf RndNum = 2 Then
If SetupFrm.OptionD(0).Value = True Then
Num1 = Int((12 - 1 + 1) * Rnd + 1)
Num2 = Int((12 - 1 + 1) * Rnd + 1)
ElseIf SetupFrm.OptionD(1).Value = True Then
Num1 = Int((25 - 1 + 1) * Rnd + 1)
Num2 = Int((25 - 1 + 1) * Rnd + 1)
Else
Num1 = Int((100 - 1 + 1) * Rnd + 1)
Num2 = Int((100 - 1 + 1) * Rnd + 1)
End If
ElseIf RndNum = 3 Then
If SetupFrm.OptionD(0).Value = True Then
Num1 = Int((5 - 1 + 1) * Rnd + 1)
Num2 = Num1 * Int((3 - 2 + 1) * Rnd + 2)
ElseIf SetupFrm.OptionD(1).Value = True Then
Num1 = Int((15 - 1 + 1) * Rnd + 1)
Num2 = Num1 * ((5 - 1 + 1) * Rnd + 1)
Else
Num1 = Int((100 - 1 + 1) * Rnd + 1)
Num2 = Num1 * ((10 - 1 + 1) * Rnd + 1)
End If
ElseIf RndNum = 4 Then
If SetupFrm.OptionD(0).Value = True Then
Num1 = Int((10 - 1 + 1) * Rnd + 1)
Num2 = Int((2 - 0 + 1) * Rnd + 1)
ElseIf SetupFrm.OptionD(1).Value = True Then
Num1 = Int((10 - 1 + 1) * Rnd + 1)
Num2 = Int((4 - 1 + 1) * Rnd + 1)
Else
Num1 = Int((10 - 1 + 1) * Rnd + 1)
Num2 = Int((10 - 0 + 1) * Rnd + 1)
End If
Else
If SetupFrm.OptionD(0).Value = True Then
Num1 = Int((2 - 0 + 1) * Rnd + 1)
Num2 = Int((10 - 1 + 1) * Rnd + 1) ^ Num1
ElseIf SetupFrm.OptionD(1).Value = True Then
Num1 = Int((4 - 1 + 1) * Rnd + 1)
Num2 = Int((10 - 1 + 1) * Rnd + 1) ^ Num1
Else
Num1 = Int((10 - 0 + 1) * Rnd + 1)
Num2 = Int((10 - 1 + 1) * Rnd + 1) ^ Num1
End If
End If
'--------------------------------------------------
'Now we are generating the answers and showing out the problem
'--------------------------------------------------
If RndNum = 0 Then
RNum1 = Num1
RNum2 = Num2
NumA = Val(RNum1) + Val(RNum2)
Problem.Text = RNum1 & "+" & RNum2 & "=?"
ElseIf RndNum = 1 Then
If Num1 > Num2 Then
RNum1 = Num1
RNum2 = Num2
ElseIf Num2 > Num1 Then
RNum1 = Num2
RNum2 = Num1
Else
RNum1 = Num1
RNum2 = Num2
End If
NumA = RNum1 - RNum2
Problem.Text = RNum1 & "-" & RNum2 & "=?"
ElseIf RndNum = 2 Then
If Int((2 - 1 + 1) * Rnd + 1) = 1 Then
RNum1 = Num1
RNum2 = Num2
Else
RNum1 = Num2
RNum2 = Num1
End If
NumA = RNum1 * RNum2
Problem.Text = RNum1 & "╫" & RNum2 & "=?"
ElseIf RndNum = 3 Then
RNum1 = Num2
RNum2 = Num1
NumA = RNum1 / RNum2
Problem.Text = RNum1 & "≈" & RNum2 & "=?"
ElseIf RndNum = 4 Then
RNum1 = Num1
RNum2 = Num2
NumA = RNum1 ^ RNum2
Problem.Text = RNum1 & "^" & RNum2 & "=?"
Else
RNum1 = Num2
RNum2 = Num1
NumA = RNum1 ^ (1 / RNum2)
Problem.Text = RNum1 & "^1/" & RNum2 & "=?"
End If
'--------------------------------------------------
AnswerN = NumA 'Save the answer for further uses
End Sub
Private Sub ExitCmd_Click() 'Unload all of the forms and exit the program
Unload SetupFrm
Unload StatsFrm
Unload Me
End
End Sub
Private Sub Form_Load() 'Setup a couple things so the program will work right
Startup
End Sub
Private Sub Form_Unload(Cancel As Integer) 'Jump to the exit sub
ExitCmd_Click
End Sub
Private Sub PauseCmd_Click()
If PauseCmd.Caption = "&Pause" Then 'If the program isn't paused then pause it
Time.Enabled = False
Answer.Locked = True 'Keep people from "exploiting" the timer pause
PauseCmd.Caption = "Un&Pause"
Else 'If the program is paused then unpause it
Time.Enabled = True
Answer.Locked = False
PauseCmd.Caption = "&Pause"
End If
End Sub
Private